<template>
  <div>
    <div class="user">
      用户名：<span>{{user}}</span>
    </div>
    <div class="button">
      <el-button color="#626aef" @click="edit" style="width: 80px;height: 50px;font-size: 18px;">修改</el-button>
    </div>
    <el-dialog v-model="dialogVisible" title="修改个人信息" width="50%" :before-close="handleClose"
      style="min-width: 400px;max-height: 600px;">
      <span>用户名：<el-input v-model="input" style="width: 50%;"></el-input></span>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="editsuccess">确定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
export default {
  components: {},
  inject: ['reload'],
  data () {
    return {
      user: sessionStorage.getItem('user'),
      input: '',
      dialogVisible: false
    }
  },
  created () { },
  mounted () { },
  methods: {
    edit () {
      this.dialogVisible = true
    },
    editsuccess () {
      this.user = this.input
      sessionStorage.setItem('user', this.input)
      this.input = ''
      this.reload()
      this.dialogVisible = false
    }
  }
}
</script>

<style scoped lang='scss'>
.dialog-footer button:first-child {
  margin-right: 10px;
}

.user {
  text-align: center;
  font-size:25px;
  margin-top: 200px;
  margin-bottom: 10px;
}
.button{
  text-align: center;
}
</style>
